home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / e_SML / bootstrap / Mosmlrun.sml < prev   
Encoding:
Text File  |  1997-07-26  |  2.4 KB  |  93 lines  |  [TEXT/Moml]

  1. (* Mosmlrun.sml  *)
  2. (* 1997 Jul 07 e *)
  3.  
  4. (* interactive use...
  5. load "Path";
  6. load "Process";
  7. load "String";
  8. load "Substring";
  9. load "AppleScript";
  10.  
  11. val home =
  12.   case Process.getEnv "PATH_TRANSLATED" of
  13.     SOME n => Path.dir n
  14.   | NONE => ":"
  15. ;
  16. chDir (home ^ "e_SML:");
  17. *)
  18.  
  19. (* this only needs to be done once per install...
  20. let val base = home ^ "src:"
  21. in
  22.   chDir base; chDir "::";
  23.   link "mosmlcomp.image"
  24.        (true,true) (* -g -noheader *)
  25.        "lorder" (base ^ "mosmllib") [(base ^ "compiler")]
  26.        ["Mainc.uo"]
  27. end;
  28. *)
  29.  
  30. open AppleScript;
  31.  
  32. exception MosmlrunErr of int * string
  33.  
  34. fun tell_run_str s =
  35.  "tell application \"mosml142run\"\n Â«event miscdosc» " ^ s ^ "\nend tell";
  36.  
  37. fun toStrStr v = "\"" ^ v ^ "\"" ;
  38.  
  39. fun prefix_ok r =
  40.   String.sub (r,0) = #"\""
  41.   andalso String.sub (r,1) = #" "
  42.   andalso String.sub (r,2) = #"\n"
  43. ;
  44.  
  45. fun run_text str =
  46.   let val r = as_run_text (tell_run_str (toStrStr str))
  47.               handle AppleScriptErr (_,s) => s
  48.   in if prefix_ok r
  49.      then let val ss = Substring.trimr 1 (Substring.extract(r, 3, NONE))
  50.           in if Substring.isPrefix str ss
  51.              then let val s1 = Substring.triml (String.size str) ss
  52.                   in if Substring.isPrefix "\n? " s1
  53.                      then let val s2 = Substring.triml 3 s1
  54.                           in if (Substring.size s2) = 0
  55.                              then ()
  56.                              else raise MosmlrunErr (1, Substring.string s2)
  57.                           end
  58.                      else raise MosmlrunErr (2, Substring.string s1)
  59.                   end
  60.              else raise MosmlrunErr (3, r)
  61.           end
  62.      else raise MosmlrunErr (4, r)
  63.   end
  64. ;
  65.  
  66. (*
  67. run_text "mosmlcomp.image -stdlib :lib -I :e_SML :e_SML:AppleScript.sml";
  68. run_text "mosmlcomp.image -I :e_SML :e_SML:AppleScript.sml";
  69. *)
  70.  
  71. fun concat_prefixing prefix strs =
  72.   String.concat (List.map (fn s => prefix ^ s) strs);
  73.  
  74. fun mosmlrun_compile lib_str opt_str incl_strs srcfile_str =
  75.   let val incl_str = concat_prefixing " -I " incl_strs
  76.       val s = (String.concat
  77.                ["mosmlcomp.image -stdlib ",lib_str," ",
  78.                 opt_str," ",incl_str," ",srcfile_str])
  79.   in print s; print"\n";
  80.      run_text s
  81.   end;
  82.  
  83. (*
  84. mosmlrun_compile ":lib" "" [":e_SML"] ":e_SML:AppleScript.sml"
  85.  handle MosmlrunErr(n,s) => print s;
  86.  
  87. mosmlrun_compile ":lib" "-P none -imptypes" [":e_SML"] ":e_SML:AppleScript.sml"
  88.  handle MosmlrunErr(n,s) => print s;
  89.  
  90. *)
  91.  
  92. (* end of mosmlrun.sml  *)
  93.